// 计算两个时间之间的时间差 多少天时分秒
export function intervalTime(startTime, endTime) { // 传入Date类型对象
  var date1 = startTime // 开始时间
  var date2 = endTime // 结束时间
  var date3 = date2.getTime() - date1.getTime()// 时间差的毫秒数
  console.log(date3)
  //  计算出相差天数
  var days = Math.floor(date3 / (24 * 3600 * 1000))
  // 计算出小时数
  var leave1 = date3 % (24 * 3600 * 1000)
  var hours = Math.floor(leave1 / (3600 * 1000))
  // 计算相差分钟数
  var leave2 = leave1 % (3600 * 1000)
  var minutes = Math.floor(leave2 / (60 * 1000))
  // 计算相差秒数
  var leave3 = leave2 % (60 * 1000)
  var seconds = Math.round(leave3 / 1000)
  return getType(['hours'], days, hours, minutes, seconds)
}

/**
 * 获取字符串
 * @param typeArr
 * @param days
 * @param hours
 * @param minutes
 * @param seconds
 * @returns {string}
 */
function getType(typeArr, days, hours, minutes, seconds) {
  var str = ''
  if (typeArr.find(item => item == 'days') != undefined) {
    str += (days + '天')
  }
  if (typeArr.find(item => item == 'hours') != undefined) {
    str += (hours + '小时')
  }
  if (typeArr.find(item => item == 'minutes') != undefined) {
    str += (minutes + '分钟')
  }
  if (typeArr.find(item => item == 'seconds') != undefined) {
    str += (seconds + '秒 ')
  }
  return str
}
